import axios from 'axios'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
const requests = axios.create({
  baseURL: 'http://127.0.0.1:8888/api/private/v1/',
  timeout: 5000,
})

// 请求拦截器 ， 封装请求头字段
requests.interceptors.request.use(config => {
  if (sessionStorage.getItem('token')) {
    // 请求头携带 token
    config.headers.Authorization = sessionStorage.getItem('token')
    
  }
  nprogress.start()
  return config
})

requests.interceptors.response.use(config => {
  
  nprogress.done()
  return config
})

export default requests

